home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / STORE.H < prev    next >
C/C++ Source or Header  |  1992-03-04  |  6KB  |  138 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* store.h */
  21. /* Assignment macros */
  22.  
  23. /*
  24.  * Macros for storing a ref.  We use macros for storing into objects,
  25.  * since the storage manager needs to be able to track stores for
  26.  * save/restore and also for global/local checking.
  27.  * We also use macros for other ref assignments, because (as it happens)
  28.  * Turbo C generates pretty awful code for doing this.
  29.  *
  30.  * There are three cases that we need to distinguish:
  31.  *    - Storing to a stack (no special action);
  32.  *    - Storing into a newly created object (set l_new);
  33.  *    - Storing into a slot of an existing object (check l_new in
  34.  *        old value, set in new value).
  35.  * The macros are called
  36.  *    <make/store><new_type><case>(place_to_store, new_value)
  37.  * where <case> is nothing for storing to the stack, _new for storing into
  38.  * a new object, and _old for storing into an existing object.
  39.  * (The _old macros also take a client name for tracing and debugging.)
  40.  * <new_type> and new_value are chosen from the following alternatives:
  41.  *    ref_assign        POINTER TO arbitrary ref
  42.  *    make_t        type (only for null and mark)
  43.  *    make_tv        type, value field name, value
  44.  *              (only for scalars, which don't have attributes)
  45.  *    make_tav    type, attributes, value field name, value
  46.  *    make_tasv    type, attributes, size, value field name, value
  47.  * There are also specialized make_ macros for specific types:
  48.  *    make_int, make_real, make_bool, make_false, make_true,
  49.  *    make_mark, make_null, make_oper.
  50.  * Not all of the specialized make_ macros have _new and _old variants.
  51.  *
  52.  * For _tav and _tasv, we must store the value first, because sometimes
  53.  * it depends on the contents of the place being stored into.
  54.  */
  55.  
  56. /*
  57.  * Define the most efficient ref assignment macro for the platform.
  58.  */
  59. #ifdef __TURBOC__
  60.     /* Move the data in two 32-bit chunks, because */
  61.     /* otherwise the compiler calls SCOPY@. */
  62.     /* The cast to void is to discourage the compiler from */
  63.     /* wanting to deliver the value of the expression. */
  64. #  define ref_assign(pto,pfrom)\
  65.     (void)((pto)->value = (pfrom)->value,\
  66.            (pto)->tas = (pfrom)->tas)
  67. #else
  68.     /* Trust the compiler and hope for the best. */
  69.     /* The MIPS compiler doesn't like the cast to void. */
  70. #  define ref_assign(pto,pfrom)\
  71.     (*(pto) = *(pfrom))
  72. #endif
  73.  
  74. /******
  75.  ****** NOTE: the declarations of alloc_save_*_mask, alloc_save_change,
  76.  ****** and alloc_refs are duplicated from save.h.
  77.  ******/
  78. extern int alloc_save_new_mask;        /* l_new if in save, 0 if not */
  79. extern int alloc_save_test_mask;    /* 0 if in save, -1 if not */
  80. extern int alloc_save_change(P2(ref *ptr, const char *client_name));
  81. #define ref_save(pto,cname)\
  82.   (void)((r_type_attrs(pto) & l_new) == alloc_save_test_mask ?\
  83.      alloc_save_change(pto, cname) : 0)
  84. #define ref_mark_new(pto) ((pto)->tas.type_attrs |= alloc_save_new_mask)
  85. #define ref_assign_new(pto,pfrom)\
  86.   (void)(ref_assign(pto,pfrom), ref_mark_new(pto))
  87. #define ref_assign_old(pto,pfrom,cname)\
  88.   (ref_save(pto,cname), ref_assign_new(pto,pfrom))
  89. extern ref *alloc_refs(P2(uint num_refs, const char *client_name));
  90.  
  91. #define make_t(pref,newtype) r_set_type(pref, newtype)
  92. #define make_t_new(pref,newtype)\
  93.   r_set_type_attrs(pref, newtype, alloc_save_new_mask)
  94. #define make_t_old(pref,newtype,cname)\
  95.   (ref_save(pref,cname), make_t_new(pref,newtype))
  96.  
  97. #define make_tav(pref,newtype,newattrs,valfield,newvalue)\
  98.   ((pref)->value.valfield = (newvalue),\
  99.    r_set_type_attrs(pref, newtype, newattrs))
  100. #define make_tav_new(pref,t,a,vf,v)\
  101.   make_tav(pref,t,(a)|alloc_save_new_mask,vf,v)
  102. #define make_tav_old(pref,t,a,vf,v,cname)\
  103.   (ref_save(pref,cname), make_tav_new(pref,t,a,vf,v))
  104.  
  105. #define make_tv(pref,newtype,valfield,newvalue)\
  106.   make_tav(pref,newtype,0,valfield,newvalue)
  107. #define make_tv_new(pref,t,vf,v) make_tav_new(pref,t,0,vf,v)
  108. #define make_tv_old(pref,t,vf,v,cname) make_tav_old(pref,t,0,vf,v,cname)
  109.  
  110. #define make_tasv(pref,newtype,newattrs,newsize,valfield,newvalue)\
  111.   (make_tav(pref,newtype,newattrs,valfield,newvalue),\
  112.    r_set_size(pref, newsize))
  113. #define make_tasv_new(pref,t,a,s,vf,v)\
  114.   (make_tav_new(pref,t,a,vf,v), r_set_size(pref,s))
  115. #define make_tasv_old(pref,t,a,s,vf,v,cname)\
  116.   (make_tav_old(pref,t,a,vf,v,cname), r_set_size(pref,s))
  117.  
  118. /* Type-specific constructor macros */
  119.  
  120. #define make_bool(pref,bval) make_tv(pref, t_boolean, index, bval)
  121. #define make_false(pref) make_bool(pref, 0)
  122. #define make_true(pref) make_bool(pref, 1)
  123.  
  124. #define make_int(pref,ival) make_tv(pref, t_integer, intval, ival)
  125. #define make_int_new(pref,ival) make_tv_new(pref, t_integer, intval, ival)
  126.  
  127. #define make_mark(pref) make_t(pref, t_mark)
  128.  
  129. #define make_null(pref) make_t(pref, t_null)
  130. #define make_null_new(pref) make_t_new(pref, t_null)
  131. #define make_null_old(pref,cname) make_t_old(pref, t_null, cname)
  132.  
  133. #define make_oper(pref,opidx,proc)\
  134.   make_tasv(pref, t_operator, a_executable, opidx, opproc, proc)
  135.  
  136. #define make_real(pref,rval) make_tv(pref, t_real, realval, rval)
  137. #define make_real_new(pref,rval) make_tv_new(pref, t_real, realval, rval)
  138.